<template>
	<!-- 自定义头部 -->
	<u-navbar title="模具入库" size="16" bgColor="#FBFBFF" :autoBack="true"
		:style="{ paddingTop: safeAreaInsets?.top + 'px' }">
		<template #right>
			<view class="u-nav-slot" style="font-size: 16px" @click="resetBtn">重置</view>
		</template>
	</u-navbar>
	<view class="baseForm">
		<view class="overhidden">
			<view>
				<view style="
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 10px;
          ">
					<scan-bar-h5 ref="scanBarRef" style="flex: 5" placeholder="请扫描或输入模具名称" @code-scanned="getScanResult"
						:key="datekey"></scan-bar-h5>

					<button style="flex: 1" class="danger-btn1" type="primary"
						@click="jump('/eam/mold/enterWarehouse/components/moldSelect')">
						选择
					</button>
				</view>
				<!-- 模具详情 -->
				<view v-show="!taskInfo?.id && loading === false" class="flex justify-center font-14"
					style="margin: 30px 0 30px 0">暂无模具信息，请录入模具编号</view>

				<ConsumablesDetachInfo v-if="taskInfo.id" :taskInfo="taskInfo"></ConsumablesDetachInfo>
				<!-- 点检详情 -->
				<view class="plan card record-content" style="margin-bottom: 20px" v-if="taskInfo.id">
					<view v-show="
              !taskInfo?.listCheckOrder[0]?.details ||
              taskInfo?.listCheckOrder[0]?.details.length === 0
            " class="flex justify-start grey-color" style="margin: 12px 0 10px">
						暂无模具点检信息
					</view>
					<view class="" v-for="(item1, index1) in taskInfo?.listCheckOrder" :key="index1">
						<view class="record-content">
							<view v-show="item1?.details == null || item1?.details?.length === 0"
								class="flex justify-center font-14" style="margin: 30px 0 30px 0">
								暂无点检信息!
							</view>

							<view class="overhidden" v-for="(item, index) in item1?.details" :key="index">
								<view>
									<view class="record-content">
										<view class="record-item">
											<view class="title_new">
												{{ item?.sopItemName || "" }}
												<u-icon v-if="
                            item?.sopItem.sopItemMethod ||
                            item.itemImages?.length > 0
                          " name="more-circle-fill" color="rgb(192, 196, 204)" size="18"
													@click="openInfoModal(item)"></u-icon>
											</view>
											<view :class="item?.sopItemResult == 0 ? 'ce45656' : ''"
												style="min-width: 50px">
												{{ item?.sopItemResult == 0 ? "不合格" : "合格" }}
											</view>
										</view>
										<view class="record-item" v-if="
                        item.sopItem.standardValue == 1 &&
                        !(
                          !item.sopItem.standardMinValue &&
                          !item.sopItem.standardMaxValue
                        )
                      ">
											<text>上下限值</text>
											<text v-if="
                          item?.sopItem.standardMinValue !==
                          item?.sopItem.standardMaxValue
                        ">
												{{ item?.sopItem.standardMinValue || "" }}-{{
                          item?.sopItem.standardMaxValue || ""
                        }}{{ item?.standardValueUnit || "" }}
											</text>
											<text v-else>{{ item?.sopItem.standardMinValue || ""
                        }}{{ item?.sopItem.standardValueUnit || "" }}</text>
										</view>
										<view class="record-item" v-if="item.sopItem.standardValue == 1">
											<view class="flex">
												实际值
												<text class="require_icon"
													v-if="item?.sopItem.sopExecute == '1'">*</text>
											</view>
											<u-input v-model="item.sopItemValue" placeholder="请输入" class="minInput"
												:class="
                          sizeColorHandle(
                            item.sopItemValue,
                            item?.sopItem.standardMinValue,
                            item?.sopItem.standardMaxValue
                          )
                        " @change="
                          computedResult(
                            item,
                            item.sopItemValue,
                            item?.sopItem.standardMinValue,
                            item?.sopItem.standardMaxValue
                          )
                        " inputAlign="right" border="none"></u-input>
											<image @click.stop="clearInputData(index1, index)"
												v-show="item.sopItemValue" src="@/static/image/delete.png"
												class="deleteIcon" />
										</view>
										<view class="record-item" v-if="item.sopItem.standardValue == 2">
											<view class="flex">
												<view style="display: flex; align-items: center">实际值<text
														class="require_icon"
														v-if="item?.sopItem.sopExecute == '1'">*</text>：</view>
												<u-radio-group v-model="item.sopItemValueId"
													:disabled="props.isRead == 1 ? true : false" @change="
                            (e) => changeDataRadio(e, item, index1, index)
                          ">
													<u-radio :customStyle="{
                              marginRight: '20px',
                              fontSize: '14px',
                            }" shape="square" v-for="(self, index2) in item.sopItem.details" :key="index2"
														:label="self.standardValue" :name="self.id"></u-radio>
												</u-radio-group>
											</view>
											<!-- <view class="flex">
												实际值
												<text class="require_icon" v-if="item?.sopItem.sopExecute == '1'">*</text>
											</view>
											<view @click="hideKeyboard1(index1, index, item.sopItem.details ?? [])" class="flex input-box">
												<u-input
													v-model="item.sopItemValue"
													border="none"
													placeholder="请选择"
													readonly
													class="minInput"
													:class="sizeColorHandle1(item.sopItemValueId, item.sopItem.details ?? [])"
												></u-input>
												<image @click.stop="clearData(index1, index)" v-show="item.sopItemValueId" src="@/static/image/delete.png" class="deleteIcon" />
											</view> -->
										</view>

										<view class="record-item" v-if="
                        item.sopItem.standardValue == 2 &&
                        item?.sopItemResult == 0
                      ">
											<view class="flex">
												<view style="display: flex; align-items: center">异常位置：</view>
												<u-radio-group v-model="item.abnormalLocation"
													:disabled="props.isRead == 1 ? true : false"
													class="error-place-radio">
													<u-radio :customStyle="{
                              marginRight: '10px',
                              fontSize: '14px',
                            }" shape="square" v-for="(
                              item, index
                            ) in useDictionaryStore().filterDictList(
                              'abnormalLocation'
                            )" :key="index" :label="item.label" :name="item.value"></u-radio>
												</u-radio-group>
											</view>
										</view>

										<!-- <view class="record-item" >
											<view class="flex">
												指导书
											</view>
											<view 
												class="flex input-box">
											<upload-image :multiple="false" :key="index" :keys="index"
												@fileChange="(list) => getImages(list, index1, index)"
												:list="item.images ?? []" :capture="capture"
												:isRead="props.isRead == 1 ? true : "></upload-image>
											</view>
										</view> -->
									</view>
									<!-- 待需要上传图片后启用 -->
									<!-- <view class="mt-8 flex" v-if="item.sopItem.sopImage == '1'">
										<upload-image :multiple="false" :key="index" :keys="index"
											@fileChange="(list) => getImages(list, index1, index)"
											:list="item.images ?? []" :capture="capture"
											:isRead="props.isRead == 1 ? true : false"></upload-image>
									</view> -->
									<!-- 待需要上传图片后启用 -->
									<view class="mt-8 flex" v-if="item.sopItem.sopImage == '1'">
										<upload-image :multiple="false" :key="index" :keys="index"
											@fileChange="(list) => getImages(list, index1, index)"
											:list="item.images ?? []" :capture="capture"
											:isRead="props.isRead == 1 ? true : false"></upload-image>
									</view>
								</view>
								<u-divider v-show="index + 1 !== item1?.details.length"></u-divider>

								<!-- 查看页面并且没有现场图片则不展示 -->
								<!-- <view>
					<view class="title flex justify-between">
						<text class="mt-4">现场图片</text>
					</view>
	
					<view class="mt-8">
						<view class="mt-8 flex">
							<upload-image :multiple="false" :keys="4545" @fileChange="getSceneImages" :list="taskInfo.images ?? []" :capture="capture"></upload-image>
						</view>
					</view>
				</view> -->
							</view>
						</view>
						<!-- 提交 -->
						<!-- <view v-if="props.isRead !=1" class="submit_btn_divTwo">
							<button type="default" class="grey_btnTwo" @click="resetFields">重 置</button>
							<button type="primary" :disabled="postLoading" :loading="postLoading" @click="submit"
								class="submit_btnTwo">确认点检</button>
						</view> -->
					</view>

					<!-- 查看页面并且没有现场图片则不展示 -->
					<!-- <view>
						<view class="title flex justify-between">
							<text class="mt-4">现场图片</text>
						</view>
				
						<view class="mt-8">
							<view class="mt-8 flex">
								<upload-image :multiple="false" :keys="4545" @fileChange="getSceneImages" :list="taskInfo.images ?? []" :capture="capture"></upload-image>
							</view>
						</view>
					</view> -->
				</view>

				<u-loading-icon class="flex justify-center mt-20" textSize="18" v-show="loading"></u-loading-icon>
				<!-- 提交 -->
				<view class="submit_btn_divTwo" style="margin-bottom: 0px">
					<button type="default" :disabled="postLoading" :loading="assetStatus == 0 && postLoading"
						class="grey_btnTwo" @click="saveBtn(0)">
						保 存
					</button>
					<!-- <button
            type="warn"
            :disabled="postLoading"
            :loading="assetStatus == 4 && postLoading"
            @click="saveBtn(4)"
            class="red_btnTwo">
            报 废
          </button> -->
					<button type="primary" v-if="isHeGe" :disabled="postLoading"
						:loading="assetStatus == 3 && postLoading" @click="saveBtn(3)" class="submit_btnTwo">
						正 常
					</button>
					<button v-if="!isHeGe" type="primary" :disabled="postLoading"
						:loading="assetStatus == 2 && postLoading" @click="saveBtn(2)" class="submit_btnTwo">
						维 修
					</button>
				</view>
			</view>
		</view>
	</view>

	<!-- 出库确认 -->
	<u-modal :show="showImportOut" ref="uModalOut" title="" :content="`已选择位置: ${position}, 是否${
      assetStatus == 3
        ? '正常'
        : assetStatus == 4
        ? '报废'
        : assetStatus == 2
        ? '维修'
        : ''
    }入库?`" confirmText="确认" showCancelButton @cancel="cancelImportOut" @confirm="saveInfo"
		:asyncClose="true"></u-modal>
	<u-modal :show="showImportCheck" ref="uModalCheck" title="" :content="`是否确认维修入库，入库后会自动创建故障报修单，报修单不可取消`"
		confirmText="确认" showCancelButton @cancel="cancelImportCheck" @confirm="confirImportCheck"
		:asyncClose="true"></u-modal>
	<!-- 树形选择器 -->
	<ba-tree-picker ref="positionPicker" :multiple="false" @select-change="positionChange" title="位置"
		:selectedData="showPositionValue" :localdata="positionList" valueKey="id" textKey="locationName"
		childrenKey="nodes" />

	<!-- 实际值选择picker -->
	<u-picker :show="showPicker" :defaultIndex="defaultIndex" :columns="currentColumns" keyName="text" immediateChange
		@cancel="showPicker = false" @confirm="changeData"></u-picker>
	<u-modal :show="showInfo" @confirm="showInfo = false">
		<view class="" style="word-break: break-word">
			<view class="" v-if="contentInfo?.sopItem?.sopItemMethod">
				作业工具：{{ contentInfo?.sopItem?.sopItemMethod ?? "" }}</view>

			<view v-if="contentInfo?.sopItem?.sopItemTool" style="word-break: break-all; margin-top: 7px">
				作业方法：{{ contentInfo?.sopItem?.sopItemTool ?? "" }}</view>

			<view class="flex">指导书</view>
			<uploadFileDetail :multiple="false" :keys="4545" :list="contentInfo.itemImages ?? []" :capture="capture">
			</uploadFileDetail>
			<!-- <upload-image :multiple="false" :keys="4545" :list="contentInfo.itemImages ?? []" :capture="capture" :isRead="props.isRead == 1 ? true : true"></upload-image> -->
		</view>
	</u-modal>

	<!-- <u-modal :show="showInfoImage" @confirm="showInfoImage = false">
		<view class="" style="word-break: break-word">
			<view class="">作业工具：{{ contentInfoImage?.sopItemMethod ?? '' }}</view>
			
			<upload-image :multiple="false" :keys="4545" @fileChange="getSceneImages" :list="taskInfo.images ?? []" :capture="capture"></upload-image>
		
		</view>
	</u-modal> -->
</template>

<script lang="ts" setup>
	import { ref, reactive, toRaw, computed, watch } from "vue";
	import { http } from "@/utils/http";
	import { mockData } from "./index";
	import UniGoodsNav from "@/components/uni-goods-nav.vue";
	import { onPageScroll, onShow, onLoad } from "@dcloudio/uni-app";
	import UploadImage from "@/components/upload-image-ssr.vue";
	import uploadFileDetail from "@/components/upload-file-detail.vue";
	import ScanBar from "@/components/scan-bar/index.vue";
	import ConsumablesDetachInfo from "@/pages/eam/mold/enterWarehouse/components/info.vue";
	import outWarehouseInfos from "@/pages/eam/mold/outWarehouse/components/outWarehouseInfo.vue";
	import { sizeColorHandle1, sizeColorHandle } from "@/utils/common";
	import { toScanCode } from "@/components/hs-scancode/scan.js";
	import dayjs from "dayjs";
	import ScanBarH5 from "@/components/ScanBarH5/ScanBarH5.vue";
	import { CommonValue, GoodsNavClick } from "@/types/type";
	import { useEamStore } from "@/stores/useEamStore";
	import { useDictionaryStore } from "@/stores/useDictionaryStore";
	// 刚进来 页面置顶
	onLoad(() => {
		uni.pageScrollTo({
			scrollTop: 0,
			duration: 0,
		});
	});

	// 获取安全距离高度
	const { safeAreaInsets } = uni.getSystemInfoSync();

	const props = defineProps({
		isRead: {
			type: String,
			default: "0", // 1是查看
		},
	});

	onShow(() => {
		getPositionList();
	});

	// 表单详情
	let formData = reactive({
		consumeCode: "",
		consumeName: "",
	});

	// 初始化页面，获取检查详情
	let taskInfo = ref<any>({});
	const loading = ref(false);

	// 表单规则定义
	const rules = ref({});

	// 获取扫码结果
	function getScanResult(result : any) {
		formData.consumeName = result;
		if (result) {
			getDeviceInfo(result);
		}
	}

	// form信息重置
	function resetData() {
		taskInfo.value = {};
		scanBarRef.value && scanBarRef.value.reset();
		datekey.value = new Date();
		formData.consumeName = "";
		uni.pageScrollTo({
			scrollTop: 0,
			duration: 100,
		});
	}

	// 重置表单信息 & 光标自动blur
	const scanBarRef = ref();
	const datekey = ref(new Date());
	function resetFields() {
		resetData();
	}

	const showImportOut = ref(false);
	const cancelImportOut = () => {
		showImportOut.value = false;
	};
	// const confirmImportOut = async () => {
	// 	// save提交
	// 	postLoading.value = true;
	// 	const result : any = await http({
	// 		method: 'POST',
	// 		url: `/eam/eammouldtaskinfo/mouldSave`,
	// 		data: {
	// 			id: taskInfo.value.id,
	// 			locationId:positionId.value
	// 		}
	// 	}).catch(() => {
	// 		postLoading.value = false;
	// 	});
	// 	if (result?.code == 200) {
	// 		uni.showToast({
	// 			title: '入库成功'
	// 		});
	// 		showImportOut.value = false
	// 		setTimeout(() => {
	// 			postLoading.value = false;
	// 			// resetFields();
	// 			uni.navigateBack();
	// 		}, 500);
	// 	}
	// }

	// 校验提交
	const uForm = ref();
	const postLoading = ref(false);

	const assetStatus = ref();

	const isStatus = ref();
	const isHeGe = computed(() => {
		// 计算是否合格
		const listCheckOrder : any = taskInfo.value.listCheckOrder || [];
		for (let i = 0; i < listCheckOrder?.length; i++) {
			const details = listCheckOrder[i]?.details;
			for (let j = 0; j < details.length; j++) {
				if (details[j]?.sopItemValue && details[j].sopItemResult == "0") {
					return false;
				}
			}
		}
		return true;
	});

	// type 保存0，正常3，报废4
	async function saveBtn(type) {
		if (!taskInfo.value.id) {
			uni.showToast({
				title: "暂无录入模具信息，不能操作",
				icon: "none",
			});
			return;
		}

		// 判断测量值是否是数字
		for (let i = 0; i < taskInfo.value.listCheckOrder.length; i++) {
			for (
				let j = 0;
				j < taskInfo.value?.listCheckOrder[i]?.details.length;
				j++
			) {
				if (
					taskInfo.value.listCheckOrder[i]?.details[j]?.sopItem.standardValue ==
					"1"
				) {
					if (
						isNaN(
							Number(taskInfo.value.listCheckOrder[i]?.details[j]?.sopItemValue)
						)
					) {
						uni.showToast({
							title: `${taskInfo.value.listCheckOrder[i].details[j].sopItemName}的实际值只能为数字`,
							icon: "none",
						});
						return false;
					}
				}
			}
		}

		// 计算是否合格
		const listCheckOrder : any = taskInfo.value.listCheckOrder;
		for (let i = 0; i < listCheckOrder.length; i++) {
			taskInfo.value.passStatus = 1;
			const details = listCheckOrder[i]?.details;
			for (let j = 0; j < details.length; j++) {
				if (details[j]?.sopItemValue && details[j].sopItemResult == "0") {
					taskInfo.value.passStatus = 0;
				}
			}
		}

		// 判断必填项是否为空  只有报废、正常、维修 需要校验是否是必填项
		if (type == 3 || type == 4 || type == 2) {
			for (let i = 0; i < taskInfo.value.listCheckOrder.length; i++) {
				for (
					let j = 0;
					j < taskInfo.value?.listCheckOrder[i]?.details.length;
					j++
				) {
					if (
						taskInfo.value.listCheckOrder[i]?.details[j]?.sopItem.sopExecute ==
						"1" &&
						!taskInfo.value.listCheckOrder[i]?.details[j]?.sopItemValue
					) {
						uni.showToast({
							title: `${taskInfo.value.listCheckOrder[i].details[j].sopItemName}的实际值不能为空`,
							icon: "none",
						});
						return false;
					}
					const images1 = taskInfo.value.listCheckOrder[i]?.details[j]?.images
					if (
						taskInfo.value.listCheckOrder[i]?.details[j]?.sopItem.sopImage == "1" && taskInfo.value.listCheckOrder[i]?.details[j]?.sopItem.sopExecute ==
						"1" && (images1?.length==0 || !images1)
					) {
						uni.showToast({
							title: `${taskInfo.value.listCheckOrder[i].details[j].sopItemName}的图片不能为空`,
							icon: "none",
						});
						return false;
					}
				}
			}
		}

		// 存储操作状态
		assetStatus.value = type;
		//弹出位置
		if (type == 0) {
			// showPositionPicker();
			saveInfo();
			// if(taskInfo.value.assetStatus=='1'||taskInfo.value.assetStatus=='3'){

			// }else{
			// 	uni.showToast({
			// 		title: '只有正常及生产模具才能入库',
			// 		icon:'none'
			// 	});
			// }
		}
		// if (type == 2) {

		//   // showPositionPicker();
		//   saveInfo();
		//   // if(taskInfo.value.assetStatus=='1'||taskInfo.value.assetStatus=='3'){

		//   // }else{
		//   // 	uni.showToast({
		//   // 		title: '只有正常及生产模具才能入库',
		//   // 		icon:'none'
		//   // 	});
		//   // }
		// }

		if (type == 2) {
			showImportCheck.value = true;
		}

		if (type == 3 || type == 4) {
			showPositionPicker();
		}
	}

	async function saveInfo() {
		// save提交
		postLoading.value = true;
		const result : any = await http({
			method: "POST",
			url: `/eam/eammouldtaskinfo/mouldSaveStore`,
			data: {
				...toRaw(taskInfo.value),
				assetStatus: assetStatus.value,
				locationId:
					assetStatus.value == 3 || assetStatus.value == 4
						? positionId.value
						: taskInfo.value.locationId,
				locationName:
					assetStatus.value == 3 || assetStatus.value == 4
						? position.value
						: taskInfo.value.locationName,
			},
		}).catch(() => {
			postLoading.value = false;
			showImportOut.value = false;
		});
		if (result?.code == 200) {
			uni.showToast({
				title: "操作成功",
			});
			postLoading.value = false;
			showImportOut.value = false;
			setTimeout(() => {
				resetBtn();
			}, 500);
		}
	}

	// 获取模具信息（接口请求）
	async function getDeviceInfo(consumeName : string) {
		loading.value = true;
		const data : any = await http({
			method: "GET",
			url: `/eam/mouldAssetInfo/checkNameIn/${consumeName}`,
			data: {},
		}).catch(() => {
			loading.value = false;

			taskInfo.value = {};
			scanBarRef.value && scanBarRef.value.reset();
			datekey.value = new Date();
			// resetFields();
		});
		// getPlanDetails();
		if (data?.data) {
			taskInfo.value = data?.data;
			scanBarRef.value && scanBarRef.value.reset();
			datekey.value = new Date();
		} else {
			taskInfo.value = {};
			scanBarRef.value && scanBarRef.value.reset();
			datekey.value = new Date();
		}
		loading.value = false;
	}
	const checkBtn = (item, isRead = 0) => {
		uni.navigateTo({
			url: `/pages/eam/mold/outWarehouse/outWarehouseCheck?mouldType=${item.mouldType}&mouldId=${item.id}&isRead=${isRead}`,
			fail: () => {
				uni.showToast({
					title: "敬请期待",
					icon: "error",
				});
			},
		});
	};

	// 重置
	const resetBtn = async () => {
		resetData();
	};

	// 位置选择
	// 显示选择器
	const positionId = ref("");
	const position = ref("");
	const positionPicker = ref();
	function showPositionPicker() {
		positionPicker.value._show();
	}
	//监听选择（ids为数组）
	const showPositionValue = ref([]);
	function positionChange(ids, names) {
		positionPicker.value._reTreeList();
		positionId.value = ids[0] ?? "";
		position.value = names ?? "";
		showPositionValue.value = ids[0] ? [ids[0]] : [];
		console.log("positionId", positionId.value);
		showImportOut.value = true;
	}

	// 清空数据
	function clearInfo() {
		positionId.value = "";
		position.value = "";
		if (positionPicker.value?._reTreeList) {
			positionPicker.value._reTreeList();
		}
	}
	// 获取位置列表
	const positionList = ref();
	async function getPositionList() {
		const { data } = await http({
			method: "POST",
			url: `/eam/locationInfo/getTree`,
			data: {},
		});
		positionList.value = data;
	}

	// 作业方法提示框

	const showInfo = ref(false);
	const contentInfo = ref("");
	function openInfoModal(data) {
		// showInfo.value = true;
		// contentInfo.value = JSON.parse(JSON.stringify(data));
		// 选择设备信息

		useEamStore().setGuideBookData(data);

		uni.navigateTo({
			url: `/pages/eam/mold/enterWarehouse/guideBook`,
			fail: () => {
				uni.showToast({
					title: "敬请期待",
					icon: "error",
				});
			},
		});
	}

	// 作业方法提示框
	const showInfoImage = ref(false);
	const contentInfoImage = ref("");
	function openInfoModalImage(data) {
		showInfoImage.value = true;
		contentInfoImage.value = JSON.parse(JSON.stringify(data));
	}

	/**
	 * 选择实际值
	 */
	const showPicker = ref(false);
	const currentColumns = reactive([[]]);
	const currentIndex = ref();
	const currentIndex1 = ref();
	const defaultIndex = ref([0]);

	/**
	 * 组织键盘弹出
	 */
	function hideKeyboard1(index1, index, list) {
		console.log("hideKeyboard", index1, index, list);
		const lists = JSON.parse(JSON.stringify(list));
		lists.forEach((item) => {
			item.text = `${item.standardValue} - ${item.resultValue == "1" ? "正常" : "异常"
				}`;
		});
		currentIndex.value = index;
		currentIndex1.value = index1;
		currentColumns[0] = lists ?? [];
		// 给原有的值,赋值picker默认index
		const sopItemValueId =
			taskInfo.value.listCheckOrder[index1].details[index].sopItemValueId;
		if (sopItemValueId) {
			const currentIndex = list.findIndex((self) => self.id === sopItemValueId);
			console.log("currentIndex", currentIndex);
			defaultIndex.value = [currentIndex];
		} else {
			defaultIndex.value = [0];
		}
		showPicker.value = true;
		uni.hideKeyboard();
	}
	function clearData(index1, index) {
		taskInfo.value.listCheckOrder[index1].details[index].sopItemValueId = "";
		taskInfo.value.listCheckOrder[index1].details[index].sopItemValue = "";
		showPicker.value = false;
	}
	function clearInputData(index1, index) {
		taskInfo.value.listCheckOrder[index1].details[index].sopItemValue = "";
	}
	function changeData(e) {
		taskInfo.value.listCheckOrder[currentIndex1.value].details[
			currentIndex.value
		].sopItemValue = e.value[0].standardValue;
		taskInfo.value.listCheckOrder[currentIndex1.value].details[
			currentIndex.value
		].sopItemValueId = e.value[0].id;
		taskInfo.value.listCheckOrder[currentIndex1.value].details[
			currentIndex.value
		].sopItemResult = e.value[0].resultValue;
		showPicker.value = false;
	}
	// changeDataRadio(e, item, index1, index)">
	function changeDataRadio(e, item, currentIndex1, currentIndex) {
		console.log("changeDataRadio", e, item);
		const current = item.sopItem.details.filter((self) => self.id === e)[0];
		if (current) {
			// 合格时异常位置置为空/不合格时给默认值
			if (current.resultValue == 1) {
				taskInfo.value.listCheckOrder[currentIndex1].details[
					currentIndex
				].abnormalLocation = "";
			} else {
				taskInfo.value.listCheckOrder[currentIndex1].details[
					currentIndex
				].abnormalLocation = "0";
			}
			taskInfo.value.listCheckOrder[currentIndex1].details[
				currentIndex
			].sopItemValue = current.standardValue ?? "";
			taskInfo.value.listCheckOrder[currentIndex1].details[
				currentIndex
			].sopItemValueId = current.id ?? "";
			taskInfo.value.listCheckOrder[currentIndex1].details[
				currentIndex
			].sopItemResult = current.resultValue ?? "";
		}
	}

	function computedResult1(item, id, list) {
		if (list.length) {
			const current = list.filter((item) => item.id === id)[0] || null;
			console.log("current", current);
			if (!current) {
				item.sopItemResult = "1";
				return;
			} else if (current.resultValue != "1") {
				item.sopItemResult = "0";
				return;
			} else {
				item.sopItemResult = "1";
				return;
			}
		}
		return "";
	}

	function computedResult(item, number, minNumber, maxNumber) {
		console.log("computedResult", item, number, minNumber, maxNumber);
		if (!number) {
			item.sopItemResult = "1";

			return;
		}
		if (!minNumber && !maxNumber) {
			item.sopItemResult = "1";

			return;
		}
		if (isNaN(Number(number))) {
			item.sopItemResult = "0";

			return;
		}
		if (minNumber === maxNumber && Number(number) != Number(minNumber)) {
			item.sopItemResult = "0";

			return;
		}
		if (minNumber != maxNumber && Number(number) < Number(minNumber)) {
			item.sopItemResult = "0";

			return;
		}
		if (minNumber != maxNumber && Number(number) > Number(maxNumber)) {
			item.sopItemResult = "0";

			return;
		}
		item.sopItemResult = "1";
	}

	// 摄像头参数设置
	const capture = ref(["camera", "album"]);
	// 获取图片
	function getImages(list, index1, index) {
		const current = JSON.parse(
			JSON.stringify(taskInfo.value.listCheckOrder[index1].details)
		)[index];
		current.images = [];
		list?.forEach((item) => {
			current.images.push(item);
		});
		const elder = JSON.parse(
			JSON.stringify(taskInfo.value.listCheckOrder[index1].details)
		);
		elder[index] = current;
		taskInfo.value.listCheckOrder[index1].details = elder;
	}

	// 获取现场图片
	function getSceneImages(list) {
		taskInfo.value.images = list;
	}

	const showImportCheck = ref(false);
	const cancelImportCheck = () => {
		showImportCheck.value = false;
	};
	const confirImportCheck = () => {
		showImportCheck.value = false;
		showPositionPicker();
	};
	// const ImportCheck = () => {
	//   showImportCheck.value = false;
	// };
	const queryBtn = () => {
		console.log(11);
	};

	function jump(item, id = "") {
		const moldName = encodeURIComponent(scanBarRef.value.scanName || "");
		uni.navigateTo({
			url: id
				? `/pages${item}?id=${id}`
				: `/pages${item}?moldName=${moldName}&type=${1}`,
			fail: () => {
				uni.showToast({
					title: "敬请期待",
					icon: "error",
				});
			},
		});
	}

	// 选择模具
	// 选择设备信息
	const moldData = computed(() => JSON.parse(useEamStore().moldData));
	// 监控设备选择id
	watch(
		() => moldData,
		async (newVal) => {
			console.log("baocuohuanxing-anzhuang");
			if (newVal.value.id) {
				console.log(newVal.value);

				setTimeout(() => {
					scanBarRef.value.assetName = newVal.value.assetName;
					getScanResult(newVal.value.assetName);
				}, 100);
			}
			setTimeout(() => {
				useEamStore().setMoldDataData({});
			}, 1000);
		},
		{
			deep: true,
			immediate: true,
		}
	);
</script>

<style lang="scss" scoped>
	@import "@/static/css/standard_item.scss";

	.upload-scan {
		padding: $uni-page-padding;
		padding-top: 5px;
		padding-bottom: 1px;
		display: flex;
		align-items: center;

		// box-shadow: 0 1px 10px 0px rgb(19 10 236 / 10%);
		.u-icon {
			margin-left: 8px;
		}
	}

	:deep(.u-search__content) {
		border-color: silver;
	}

	.submit_btnTwo {
		margin: 0px 20rpx 16rpx 10rpx;
		font-size: 16px;
		height: 45px;
		line-height: 45px;
		box-shadow: 0 1px 10px rgb(3 121 255 / 30%);
	}

	.red_btnTwo {
		margin: 0px 5rpx 16rpx 5rpx;
		font-size: 16px;
		height: 45px;
		line-height: 45px;
	}

	.grey_btnTwo {
		margin: 0px 10rpx 16rpx 20rpx;
		font-size: 16px;
		height: 45px;
		line-height: 45px;
		border: 1px solid #666;
	}

	.submit_btn_divTwo {
		position: fixed;
		display: flex;
		align-items: center;
		width: 100%;
		bottom: 0;
		z-index: 1;

		uni-button {
			flex: 1;
			border-radius: 6px;
		}
	}

	.caozuo_line {
		:deep(.u-tag) {
			padding: 1px 25px;
		}
	}

	:deep(.searchScan) {
		border: 1px solid silver;
		border-radius: 4px;
	}

	:deep(.u-navbar__content__title) {
		font-weight: 600;
	}

	.baseForm {
		margin-top: 44px;
		padding-bottom: 50px;
	}

	.danger-btn1 {
		// 更深的红色，增强警示性
		color: #fff;
		border: none;
		border-radius: 0 6px 6px 0; // 更大的圆角
		padding: 0px 16px; // 更舒适的内边距
		margin-left: -3px;
		height: 38px;
		font-size: 15px;
		font-weight: bold; // 加粗文字
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); // 添加阴影
		transition: all 0.3s ease; // 平滑过渡效果
	}
</style>